Skip to content

Change interfaces to be consistent for new Async paths (definitely breaks things)#1128

Merged
adamhathcock merged 38 commits intomasterfrom
adam/async-interface
Jan 15, 2026
Merged

Change interfaces to be consistent for new Async paths (definitely breaks things)#1128
adamhathcock merged 38 commits intomasterfrom
adam/async-interface

Conversation

@adamhathcock
Copy link
Copy Markdown
Owner

@adamhathcock adamhathcock commented Jan 12, 2026

API thinking here: #1129

This pull request introduces several improvements and clarifications to the SharpCompress codebase and documentation, focusing on enhancing async support, updating documentation for modern usage, and cleaning up code and configuration files. The most significant changes are grouped and summarized below.

Async API Enhancements and Consistency:

  • Improved async method implementations in AbstractArchive by using explicit async enumerator methods for casting and updating aggregate operations to use their async variants (e.g., AggregateAsync, AllAsync). Also added TotalUncompressedSizeAsync and clarified IsEncryptedAsync return type. [1] [2]
  • Refactored ArchiveFactory async methods to remove unnecessary ConfigureAwait(false), streamline calls, and eliminate redundant XML documentation comments, making the async API more idiomatic and easier to maintain. [1] [2] [3] [4] [5] [6] [7] [8]
  • Updated AbstractWritableArchive to implement the new IWritableAsyncArchive interface and unified interface method implementations under IWritableArchiveCommon, improving consistency for writable archives. [1] [2]

Documentation Updates and Modernization:

  • Overhauled docs/API.md to reflect modern async usage patterns, clarify types (IEntryIArchiveEntry), provide more accurate code samples, and expand on supported compression and archive types. Also updated extraction and writer usage to reflect best practices and new APIs. [1] [2] [3] [4] [5] [6] [7]

Configuration and Project Maintenance:

  • Added Microsoft.NET.ILLink.Task package to central package management and enabled CentralPackageTransitivePinningEnabled in build properties to improve dependency management. [1] [2]
  • Removed the .editorconfig rule that set CS1998 (async method lacks 'await') as an error, likely to reduce noise for intentionally synchronous async methods.
  • Updated the solution file to add .gitignore and remove obsolete documentation files, reflecting a cleanup of project structure.

Minor Documentation and Typo Fixes:

  • Fixed a typo in the property name (TotalUncompressSizeTotalUncompressedSize) for clarity and consistency.
  • Removed an outdated note about multi-framework differences from AGENTS.md.

Change return types from ValueTask<T> to direct interface types (IAsyncArchive, IAsyncReader, IWriter) for wrapper methods that don't perform async work. This eliminates unnecessary async state machine allocations while maintaining the same public API behavior.

Changes:
- Interface definitions: Updated IArchiveFactory, IMultiArchiveFactory, IReaderFactory, IWriterFactory
- Concrete factories: Updated archive factories (Zip, Tar, Rar, GZip, SevenZip) and reader-only factories (Ace, Arc, Arj)
- Static factory methods: Updated ReaderFactory, ArchiveFactory, WriterFactory to use new signatures
- Archive classes: Updated static OpenAsync methods in ZipArchive, TarArchive, RarArchive, SevenZipArchive, GZipArchive
- Supporting changes: Updated Factory.cs and async polyfills

Performance benefit: Reduced GC pressure by eliminating unnecessary state machine overhead for non-async wrapper methods.
…y.OpenAsync and use IAsyncReader

- Removed 'await' keyword before ReaderFactory.OpenAsync() calls since the method returns IAsyncReader directly (not Task)
- Changed ZipReader.Open() to ReaderFactory.OpenAsync() in Zip64AsyncTests.ReadForwardOnlyAsync()
- Changed TarReader.Open() to ReaderFactory.OpenAsync() in TarReaderAsyncTests.Tar_BZip2_Entry_Stream_Async()
- Fixed EntryStream disposal from 'await using' to 'using' since EntryStream doesn't implement IAsyncDisposable
- These changes fix compilation errors where async methods were being called on IReader (synchronous) instead of IAsyncReader (asynchronous)
Copilot AI review requested due to automatic review settings January 12, 2026 15:04
@adamhathcock adamhathcock marked this pull request as draft January 12, 2026 15:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants